package com.hanhanxiaochong.zhongxiangchuanmei.view.home.act;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.VipGradeItem;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.main.adapter.HomeVipPageAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.act.RechargeActivity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/4/23.
 * Desc   : 首页-会员专享
 */

public class HomeVipActivity extends BaseActivity {

    @BindView(R.id.img_left)
    ImageView imgLeft;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.btn_recharge)
    Button btnRecharge;
    private List<VipGradeItem> list;

    public static Intent createIntent(Context context) {
        return new Intent(context, HomeVipActivity.class);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_home_vip);
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void init() {
        setTopView();
        RetrofitSource.createApi(HttpPostService.class).grade()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<List<VipGradeItem>>>(this) {
                    @Override
                    public void onSuccess(ResponseBase<List<VipGradeItem>> response) {
                        list = response.getData();
                        HomeVipPageAdapter pageAdapter = new HomeVipPageAdapter(HomeVipActivity.this, list);
                        viewpager.setAdapter(pageAdapter);
                    }
                });
    }

    private void setTopView() {
        imgLeft.setImageResource(R.mipmap.icon_close_black);
        txtTitle.setText("会员专享");
    }


    @OnClick({R.id.ll_leftview, R.id.btn_recharge})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_leftview:
                finish();
                break;
            case R.id.btn_recharge:
                Intent intent = new Intent(this, RechargeActivity.class);
                startActivity(intent);
                break;
        }
    }
}
